/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.campusinfocompany.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lczyfz.campusinfo.modules.campusinfocompany.entity.LinkCompany;
import com.lczyfz.campusinfo.modules.campusinfocompany.service.LinkCompanyService;
import com.lczyfz.campusinfo.modules.jobmesmanage.entity.StuJobSearch;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.campusinfocompany.entity.CompanySearch;
import com.lczyfz.campusinfo.modules.campusinfocompany.service.CompanySearchService;

import java.util.List;

/**
 * 公司权限Controller
 * @author zms
 * @version 2018-04-18
 */
@Controller
@RequestMapping(value = "${adminPath}/campusinfocompany/companySearch")
public class CompanySearchController extends BaseController {

	@Autowired
	private CompanySearchService companySearchService;
	@Autowired
	private LinkCompanyService linkCompanyService;
	@ModelAttribute
	public CompanySearch get(@RequestParam(required=false) String id) {
		CompanySearch entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = companySearchService.get(id);
		}
		if (entity == null){
			entity = new CompanySearch();
		}
		return entity;
	}
	
	@RequiresPermissions("campusinfocompany:companySearch:view")
	@RequestMapping(value = {"list", ""})
	public String list(CompanySearch companySearch, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CompanySearch> page = companySearchService.findPage(new Page<CompanySearch>(request, response), companySearch); 
		model.addAttribute("page", page);
		return "modules/campusinfocompany/companySearchList";
	}
	@RequiresPermissions("campusinfocompany:companySearch:view")
	@RequestMapping(value = "detail")
	public String detail(CompanySearch companySearch, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CompanySearch> page = companySearchService.findPage(new Page<CompanySearch>(request, response), companySearch);
		model.addAttribute("page", page);
		return "modules/campusinfocompany/companySearchList";
	}
	@RequiresPermissions("campusinfocompany:linkCompany:edit")
	@RequestMapping(value = "delete")
	public String delete(LinkCompany linkCompany, RedirectAttributes redirectAttributes) {
		linkCompanyService.delete(linkCompany);
		addMessage(redirectAttributes, "删除用户的归属那家公司成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfocompany/companySearch/?repage";
	}
}